package com.apes.hr.recruit.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.Employee;
import com.apes.hr.base.model.Job;
import com.apes.hr.base.model.Rank;
import com.apes.hr.base.model.WorkPost;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：聘用合同
 * @author HuJianlin
 * @create 2018-05-05 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = EmployContract.CONST_TABLE_NAME)
public class EmployContract extends Model {
    public static final String CONST_TABLE_NAME = "hr_Employ_Contract";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "聘用合同", prefix = "H", padding = 7)
    private String id;   //合同号

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Employee_id", referencedColumnName = "ID")
    private Employee employee; //员工

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "nature", referencedColumnName = "id")
    private Enumeration nature;    // 合同性质（协议版本）

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Contract_version", referencedColumnName = "id")
    private Enumeration contractVersion;    // 合同版本（hrContractVersion）

    @Column(name = "probation_pay", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double probationPay;    // 试用期工资

    @Column(name = "regular_pay", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double regularPay;    // 转正后工资

    @Column(name = "proba_min_pay", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double probaMinPay;    // 试用期保底工资

    @Column(name = "regular_min_pay", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double regularMinPay;    // 转正后保底工资

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "agree_entry_date")
    private Date agreeEntryDate;    // 约定入职时间

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "first_payday")
    private Date firstPayday; // 首个计薪日

    @Column(name = "Probation_period")
    private int probationPeriod;    // 试用期

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "probation_begin")
    private Date probationBegin; // 试用期起

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "probation_end")
    private Date probationEnd;  // 试用期止

    @Column(name = "contract_term", nullable = false)
    private int contractTerm;    // 合同期

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "contract_begin")
    private Date contractBegin;    // 合同期起

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "contract_end")
    private Date contractEnd;    // 合同期止

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "internship_begin")
    private Date internshipBegin;//协议期起

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "internship_end")
    private Date internshipEnd;//协议期止

    @Column(name = "is_2nd_entry", nullable = false, columnDefinition = "number(1,0) default 0")
    private boolean is2ndEntry = false;    // 是否二次入职

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id", referencedColumnName = "id")
    private WorkPost post; //岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "job_id", referencedColumnName = "id")
    private Job job; //职位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rank_id", referencedColumnName = "id")
    private Rank rank; //职级

    @Column(name = "state", length = 10, nullable = false)
    private String state; //单据状态： ('create','创建'), ('done','审核'),('repeal','终止'), ('delete', '删除')

    @Column(name = "renew_pay",  columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("续签时工资")
    private double renewPay;

    @Column(name = "remark", length = 4000)
    @Comment("备注")
    private String remark;
}
